package com.createidea.scrumfriend.service.story;

import java.util.List;

import com.createidea.scrumfriend.dao.story.StoryDao;
import com.createidea.scrumfriend.to.ProjectTo;
import com.createidea.scrumfriend.to.SprintTo;
import com.createidea.scrumfriend.to.StoryTo;

public class StoryServiceImpl implements StoryService {

	private StoryDao storyDao;

	public StoryDao getStoryDao() {
		return storyDao;
	}

	public void setStoryDao(StoryDao storyDao) {
		this.storyDao = storyDao;
	}

	
	@Override
	public void updateStory(StoryTo story) {
		// TODO Auto-generated method stub
		story.setStatus(3);
		storyDao.updateStory(story);
	}

	@Override
	public void updateStoryStatus(String card_id, String box_id,String sprintId, String user) {
		// TODO Auto-generated method stub
		StoryTo story=storyDao.getStoryById(card_id);	
		int status=Integer.parseInt(box_id);
		if(status==0)
			story.setSprint(null);
		else
			story.setSprint(new SprintTo(sprintId));
		story.setStatus(status);		
		storyDao.updateStory(story);
	}

	@Override
	public void createStory(StoryTo story,String projectId) {
		
		story.setStatus(0);
		if(projectId!=null)
			story.setProject(new ProjectTo(projectId));
		storyDao.createStory(story);
	}

	@Override
	public List<StoryTo> getStoriesForProject(String projectId) {
		
		return storyDao.getStoriesForProject(projectId);
	}

	@Override
	public List<StoryTo> getStoriesForProjectByStatus(String projectId,int status) {
		
		return storyDao.getStoriesForProjectByStatus(projectId,status);
		 
	}

	@Override
	public float calculateTotalPointsForProject(ProjectTo project) {
	
		return storyDao.calculateTotalPointsForProject(project);
	}

	@Override
	public float calculateCompletedPointForProject(ProjectTo project) {
	
	    return storyDao.calculateCompletedPointForProject(project);
	}

	@Override
	public float calculateRemainingPointForProject(ProjectTo project) {
		return storyDao.calculateRemainingPointForProject(project);
	}

	@Override
	public List<StoryTo> getStoriesForSprintByStatus(String sprintId, int status) {
		// TODO Auto-generated method stub
		return storyDao.getStoriesForSprintByStatus(sprintId,status);
	}
	  
}
